<template>
  <div class="goodsbox">
    <el-row>
      <el-col :span="3">
        <el-button type="success" @click="addhandler">添加商品</el-button>
      </el-col>
      <el-col :span="10">
        <el-input
        v-model="pageInfo.query"
        placeholder="搜索商品"
        @input="goodsList" />
      </el-col>
    </el-row>
    <!-- 分页器 -->
    <div class="pages">
      <div class="demo-pagination-block">
        <el-pagination
          :hide-on-single-page="true"
          v-model:current-page="pageInfo.pagenum"
          v-model:page-size="pageInfo.pagesize"
          :page-sizes="[10, 20, 30, 40]"
          :background="true"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageInfo.total"
          @size-change="goodsList"
          @current-change="goodsList"
        />
      </div>
    </div>

   <!-- 表格列表 -->
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column type="index" label="序号" width="60" />
      <el-table-column prop="goods_id" label="商品编号" width="100" />
      <el-table-column prop="goods_name" label="商品介绍" width="200" />
      <el-table-column prop="goods_price" label="商品价格" width="100" />
      <el-table-column prop="goods_number" label="商品库存" width="100" />
      <el-table-column label="操作" width="150">
        <template #default="{  }">
          <el-tooltip
            class="box-item"
            effect="dark"
            content="编辑"
            placement="left-start"
          >
          <el-button type="primary" :icon="'User'" circle />
          </el-tooltip>
          <el-tooltip
            class="box-item"
            effect="dark"
            content="分配角色"
            placement="top"
          >
            <el-button type="success" :icon="'Check'" circle />
          </el-tooltip>

          <el-popconfirm title="真的要删除这个用户吗？" >
            <template #reference>
              <el-button type="danger" :icon="'Delete'" circle />
            </template>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <hr>
  <!-- 分页器 -->
    <div class="pages">
      <div class="demo-pagination-block">
        <el-pagination
          :hide-on-single-page="true"
          v-model:current-page="pageInfo.pagenum"
          v-model:page-size="pageInfo.pagesize"
          :page-sizes="[10, 20, 30, 40]"
          :background="true"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageInfo.total"
          @size-change="goodsList"
          @current-change="goodsList"
        />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'oaGoods',
  data () {
    return {
      tableData: [],
      goodsLists: [],
      pageInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10,
        total: 200
      }
    }
  },
  methods: {
    async goodsList () {
      const listres = await this.$http.get('goods', { params: this.pageInfo })

      if (listres.meta.status !== 200) return
      this.pageInfo.total = listres.data.total
      this.tableData = listres.data.goods
    },
    // 跳转到添加商品
    addhandler () {
      this.$router.push('/add')
    }
  },
  created () {
    this.goodsList()
  }
}

</script>

<style scoped lang="scss">
.pages{
  margin: 5px 0;
}
</style>
